const mongoose = require('mongoose')
const Image = mongoose.model('Image')

const rankfn = async() => {
    const rankStats = await Image.find()
      .sort({"visit": -1})
      .limit(10)
    return {
        ...rankStats
    }
}

// const rankfn = () => Promise.all([
//     Image.aggregate()
//       .group({
//           _id: null,
//           numOfImages: {$sum: 1},
//           numOfLikes: {$sum: '$likes'},
//           numOfVisits: {$sum: '$visit'}
//       })
// ]).then((obj1) => ({
//     ...obj1[0]
// }))

module.exports = rankfn